package kaiseki.de.managerwebsite;

import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Table;

public class tableClickListener implements ClickListener {
	private String number;
	private IndexedContainer uco;
	private MySQLData data;
	private Table list;
	
	tableClickListener(String number,IndexedContainer uco,MySQLData data, Table list){
		this.number=number;
		this.uco=uco;
		this.data=data;
		this.list=list;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1948010255627296601L;

	@Override
	public void buttonClick(ClickEvent event) {
		// TODO Auto-generated method stub
		try {
			if(!number.equals("all")){
			this.uco.removeAllItems();
			IndexedContainer ic=this.data.getUnPayOrdersFromTable(this.number);
			for(int i=0;i<ic.size();i++){
				Object idn=ic.getIdByIndex(i);
				Object id =this.uco.addItem();
				this.uco.getContainerProperty(id, "id").setValue((String)ic.getContainerProperty(idn, "id").getValue());
				this.uco.getContainerProperty(id, "tablenumber").setValue((String)ic.getContainerProperty(idn, "tablenumber").getValue());
				this.uco.getContainerProperty(id, "cost").setValue((String)ic.getContainerProperty(idn, "cost").getValue());
				this.uco.getContainerProperty(id, "item").setValue((String)ic.getContainerProperty(idn, "item").getValue());
				this.uco.getContainerProperty(id, "date").setValue((String)ic.getContainerProperty(idn, "date").getValue());
			}
			
			list.setContainerDataSource(uco);
			} else{
				
				this.uco.removeAllItems();
				IndexedContainer ic=this.data.getOrders("unpay");
				for(int i=0;i<ic.size();i++){
					Object idn=ic.getIdByIndex(i);
					Object id =this.uco.addItem();
					this.uco.getContainerProperty(id, "id").setValue((String)ic.getContainerProperty(idn, "id").getValue());
					this.uco.getContainerProperty(id, "tablenumber").setValue((String)ic.getContainerProperty(idn, "tablenumber").getValue());
					this.uco.getContainerProperty(id, "cost").setValue((String)ic.getContainerProperty(idn, "cost").getValue());
					this.uco.getContainerProperty(id, "item").setValue((String)ic.getContainerProperty(idn, "item").getValue());
					this.uco.getContainerProperty(id, "date").setValue((String)ic.getContainerProperty(idn, "date").getValue());
				}
				list.setContainerDataSource(uco);
			}
			//orderList.setContainerDataSource(ico);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
